package news_create_config

import (
	"fmt"
	createConfigDto "news_for_deepseek_interface/dto/admin/news/create_config"
	"news_for_deepseek_interface/model"
	"news_for_deepseek_interface/model/news"
)

func All(params createConfigDto.AllRequest) (response createConfigDto.AllResponse, err error) {
	db := model.GetInstance().GetDB()

	var data []news.NewsCreateConfig
	if err = db.Model(&news.NewsCreateConfig{}).
		Order("created_at DESC,id desc").
		Find(&data).Error; err != nil {
		err = fmt.Errorf("数据查询失败%s", err.Error())
		return
	}

	// 构建响应
	response = createConfigDto.AllResponse{
		List: make([]createConfigDto.NewsCreateConfigAll, 0),
	}

	for _, v := range data {

		response.List = append(response.List, createConfigDto.NewsCreateConfigAll{
			Id:    v.Id,
			Title: v.Title,
		})
	}

	return
}
